<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>p2_CSS选择器</title>
    <style>
        .a{
            color: red;
        }
        div{
            width: 100px;
            height: 100px;
            background-color: yellow;
        }
        #d2{
            border: 5px solid red;
        }
        .error{
            background-color: red;
            color: white;
        }
        .success{
            background-color: green;
            color: white;
        }
        .msg{
            color: blue;
        }
        #d2,h4,.error{
            text-decoration: underline;
        }
        * {
            font-style: italic;
        }
        /*属性选择器*/
        input[type="text"]{
            background-color: yellow;
        }
        /*伪类选择器*/
        a:link{ /* 选中超链接未被访问过的状态 */
            color: gray;
        }
        a:visited{ /* 选中超链接已被访问过的状态 */
            color: green;
        }
        a:hover{ /* 选中超链接悬停的状态 */
            color: orange;
        }
        a:active{ /* 选中超链接激活的状态 */
            color: red;
        }
        /*后代选择器:空格,选中所有包含在内的下层元素:儿子、孙子、重孙子...*/
        #d1 span {
            color: cyan;
        }
        /*直接子代选择器:大于号,只选中下一级元素,不会继续向下选择*/
        #d1>div>span{
            color: red;
        }
        /*hover悬停不是超链接独有的选择器*/
        #d3:hover{
            background-color: purple;
        }
    </style>
</head>
<body>
<div id="d1">
    <span>1</span>
    <div>
        <span>2</span>
        <p>测试文字</p>
        <p>我是<span>测试</span>段落</p>
    </div>
    <span>3</span>
</div>
<br>
<a href="http://www.baidu.com">超链接1</a>
<a href="abc">超链接2</a>
<h4 class="a">我是标题</h4>
<p>我是段落</p>
<a href="#">我是超链接</a>
<h4 id="d2">我是标题2</h4>
<div>我是div1</div>
<div>我是div2</div>
<div id="d3">我是div3</div>
<hr>
<span class="error msg">用户名已被占用</span>
<span class="error msg">密码长度不正确</span>
<span class="error msg">两次密码不一致</span>
<br>
<span class="success msg">用户名可以使用</span>
<span class="success msg">手机号已验证</span>
<span class="success msg">邮箱格式正确</span>
<hr>
<input type="text">
<input type="password">
</body>
</html>